package console.view;

import java.util.ArrayList;
import java.util.HashMap;

import accessory.Command;

public class CommandHandler {

	
	private static HashMap<String, Command> commandStack;
	
	
	public static void addCommand(String ident, Command command){
		getCommandStack().put(ident, command);
	}
	
	
	public void executeCommand(String ident){
		if(getCommandStack().get(ident) != null){
			commandStack.get(ident).execute(new String[0]);
		}
	}
	
	public void executeCommand(String ident, ConsoleContainer container){
		executeCommand(ident, new String[0], container);
	}
	
	public void executeCommand(String ident, String[] args, ConsoleContainer container){
		container.printText(ident+";");
		if(getCommandStack().get(ident) != null){			
			container.printText(commandStack.get(ident).execute(args));
		} else {
			container.printText("Command not found: " + ident+";");
		}
	}
	
	private static HashMap<String, Command> getCommandStack(){
		if(commandStack == null){
			commandStack = new HashMap<String, Command>();
		}
		return commandStack;
	}
	
}
